package com.hpu.springboot01.controller;

import com.hpu.springboot01.pojo.UserEntity;
import com.hpu.springboot01.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//springboot发现类上面加了@RestController,会自动为类创建对象
public class RegisterController {

    //@Service class RegisterServiceImpl
    //springboot为RegisterServiceImpl类创建对象，对象放到了springboot容器中

    @Autowired //springboot在容器中找一个对象赋值给属性
    RegisterService registerService;

    @RequestMapping("/register")
    //当springboot发现用户请求的地址是/register，springboot调用方法来处理请求
    //http://127.0.0.1:8081/doc.html
    public String register(UserEntity userEntity){
        //1,接收浏览器发过来的数据
        //2,调用业务层
        boolean result = registerService.register(userEntity.getUsername());
        //3,返回结果给浏览器
        if (result){
            return "注册成功";
        }else {
            return  "注册失败";
        }
    }
}
